package gameBasics;

import utli.ImageUtil;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Objects;

public class ResourceManager {

    public static BufferedImage tankL, tankU, tankR, tankD;
    public static BufferedImage bulletNormal;
    public static BufferedImage enemyTank_1L, enemyTank_1U, enemyTank_1R, enemyTank_1D;
    public static BufferedImage enemyTank_2L, enemyTank_2U, enemyTank_2R, enemyTank_2D;
    public static BufferedImage enemyTank_3L, enemyTank_3U, enemyTank_3R, enemyTank_3D;
    public static BufferedImage enemyTank_4L, enemyTank_4U, enemyTank_4R, enemyTank_4D;
    public static BufferedImage wall, iron, grass, commandPost;
    public static BufferedImage[] explosions = new BufferedImage[6];

    static {
        try {
            //主坦克贴图
            tankL = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/mainTank_l.png")));
            tankU = ImageUtil.rotateImage(tankL,90);
            tankR = ImageUtil.rotateImage(tankL,180);
            tankD = ImageUtil.rotateImage(tankL,-90);
            //炮弹贴图
            bulletNormal = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/bullet_normal.png")));
            //敌方坦克(level-1)贴图
            enemyTank_1L = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/enemyTank_1_l.png")));
            enemyTank_1U = ImageUtil.rotateImage(enemyTank_1L,90);
            enemyTank_1R = ImageUtil.rotateImage(enemyTank_1L,180);
            enemyTank_1D = ImageUtil.rotateImage(enemyTank_1L,-90);
            //敌方坦克(level-2)贴图
            enemyTank_2L = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/enemyTank_2_l.png")));
            enemyTank_2U = ImageUtil.rotateImage(enemyTank_2L,90);
            enemyTank_2R = ImageUtil.rotateImage(enemyTank_2L,180);
            enemyTank_2D = ImageUtil.rotateImage(enemyTank_2L,-90);
            //敌方坦克(level-3)贴图
            enemyTank_3L = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/enemyTank_3_l.gif")));
            enemyTank_3U = ImageUtil.rotateImage(enemyTank_3L,90);
            enemyTank_3R = ImageUtil.rotateImage(enemyTank_3L,180);
            enemyTank_3D = ImageUtil.rotateImage(enemyTank_3L,-90);
            //敌方坦克(level-3)贴图
            enemyTank_4U = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/enemyTank_4_u.gif")));
            enemyTank_4L = ImageUtil.rotateImage(enemyTank_4U,-90);
            enemyTank_4R = ImageUtil.rotateImage(enemyTank_4U,90);
            enemyTank_4D = ImageUtil.rotateImage(enemyTank_4U,180);
            //爆炸贴图
            for(int i = 0; i < 6; i++){
                explosions[i] = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/explosion_" + (i + 1) + ".png")));
            }
            //object贴图
            wall = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/wall.png")));
            iron = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/iron.png")));
            grass = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/grass.gif")));
            commandPost = ImageIO.read(Objects.requireNonNull(ResourceManager.class.getClassLoader().getResourceAsStream("images/commandPost.png")));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
